﻿using System;
using NetDon.OA.Data.EntityClasses;
using NetDon.Utilities;

namespace NetDon.OA.Portal.Admin
{
    [Navigation("修改密码")]
    public partial class ChangePassword : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            var context = ServiceContainer.GetService<ApplicationContext>();
            UserEntity userEntity = new UserEntity(context.UserId);
            if (!userEntity.IsNew)
            {
                if (userEntity.Password == MiscUtilities.ComputePasswordHash(txtOldPassword.Text.Trim()))
                {
                    userEntity.Password = MiscUtilities.ComputePasswordHash(txtNewPassword.Text.Trim());
                    if (userEntity.Save())
                    {
                        base.Success("密码保存成功!");
                        //  base.Success(GetResourceString("PasswordSaveOK"));
                    }
                }
                else
                {
                    base.Alert("旧密码不正确.");
                    // base.Success(GetResourceString("OriginalPasswordError"));

                }
            }
        }
    }
}
